#include "Com.hpp"
#include <functional>
#include <memory>
#include <iostream>
#include "InetAddr.hpp"
#include "NetCal.hpp"
#include "Socket.hpp"
#include "TcpServer.hpp"

void Usage()
{
    std::cout <<"./TcpClient server_ip server_port" << std::endl;
}
void GetData(int& x , int& y, char& oper)
{
    std::cout << "Plase Enter#: " <<std::endl;
    std::cin >> x;
    std::cout << "Plase Enter#: " <<std::endl;
    std::cin >> y;
    std::cout << "Plase Enter#: " <<std::endl;
    std::cin >> oper;
}
int main(int argc , char* args[])
{
    if(argc != 3)
    {
        Usage();
        return 2;
    }

    InetAddr server(args[1] , std::stoi(args[2]));

    std::shared_ptr<Socket> sock =std::make_unique<TcpSocket>();
    sock->BuildTcpClientSocketMethod();
    sock->Connect(server);
    std::unique_ptr<Protocol> pro = std::make_unique<Protocol>();
    while(true)
    {
        int x,y;
        char oper;
        GetData(x , y , oper);

        std::string package = pro->BuildRequestMethod(x , y , oper);
        sock->Send(package);

        Response res;
        std::string str;
        pro->GetResponse(str, sock , res);//GetResponse这个方法还有问题
        res.ShowResult();
    }
    sock->Close();
    return 0;
}